<template xmlns="http://www.w3.org/1999/html">
  <button @click="count++">count is: {{ count }}</button>
  <form>
    <input v-model="username" placeholder="username"/>
    <input v-model="password" placeholder="password"/>
    <button type="button" @click="Login"> 登陆</button>
  </form>
  <p>Edit <code>components/HelloWorld.vue</code> to test hot module replacement.</p>
</template>

<script>
import {setRefreshToekn, setToken, setTokenHead} from "../utils/auth";
import {setUserInfo} from "../utils/owninfo";
import request from '../utils/axios'

export default {
  name: 'HelloWorld',
  props: {
    // msg: String
  },
  data() {
    return {
      count: 0,
      username: "",
      password:"",
    }
  },
  methods: {
    Login(){
      request({
        url: '/auth/oauth/token',
        method: 'post',
        params:{
          username: this.username,
          password: this.password,
          grant_type: 'password',
          client_id: 'client-app',
          client_secret: '123456',
        }
      }).then(response => {
        console.info(response)
        setTokenHead("Bearer")
        setToken(response.access_token)
        setRefreshToekn(response.refresh_token)
        setUserInfo(response.id)
      }).catch(error => {
        console.info(error)
      })
    },
  }
}
</script>
